<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-irdist-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     MSDIST,              sensorI2CCustomFastSkipStates9V)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-irdist-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * MSAC-driver.h provides an API for the Mindsensors Acceleration Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: More comments</span>
<span class="comment"> * - 0.3: Fixed stupid typo</span>
<span class="comment"> * - 0.4: Removed sensor configuration call, now done automatically.</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 06 July 2010</span>
<span class="comment"> * version 0.4</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="mindsensors-irdist_8h.html" title="Mindsensors DIST-Nx driver.">drivers/mindsensors-irdist.h</a>&quot;</span>

task main () {
  <span class="keywordtype">int</span> distance = 0;
  <span class="keywordtype">int</span> voltage = 0;
  <span class="keywordtype">int</span> mindist = 0;
  <span class="keywordtype">int</span> maxdist = 0;
  <span class="keywordtype">string</span> type;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Mindsensors&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;DIST-nx&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 1&quot;</span>);

  wait1Msec(2000);

  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
  eraseDisplay();

  <span class="comment">// Read the minimum distance the sensor can &quot;see&quot;</span>
  mindist = <a name="a0"></a><a class="code" href="group__msdist.html#ga3d87990cb848e2a6a98fdd9dc7aa15e0">MSDISTreadMinDist</a>(MSDIST);

  <span class="comment">// Read the maximum distance the sensor can &quot;see&quot;</span>
  maxdist = <a name="a1"></a><a class="code" href="group__msdist.html#gae96736e03c9eedc181771494dfbc9455">MSDISTreadMaxDist</a>(MSDIST);

  <span class="comment">// Get the type of Sharp IR module connected to the sensor</span>
  <span class="keywordflow">switch</span>(<a name="a2"></a><a class="code" href="group__msdist.html#gadfb19f55b0e87638753d5e3d894479c0">MSDISTreadModuleType</a>(MSDIST)) {
    <span class="keywordflow">case</span> <a name="a3"></a><a class="code" href="group__msdist.html#gad60276924b4b8bc56d60480d33110051">MSDIST_GP2D12</a>:  type = <span class="stringliteral">&quot; GP2D12&quot;</span>; <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> <a name="a4"></a><a class="code" href="group__msdist.html#gaca985347e2d1ec1bce26af8ac8aff12d">MSDIST_GP2D120</a>: type = <span class="stringliteral">&quot;GP2D120&quot;</span>; <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> <a name="a5"></a><a class="code" href="group__msdist.html#ga6660666763ce1ed208cd5dacafea1fab">MSDIST_GP2YA02</a>: type = <span class="stringliteral">&quot;GP2YA02&quot;</span>; <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> <a name="a6"></a><a class="code" href="group__msdist.html#ga958340025be224b9008490ad04412591">MSDIST_GP2YA21</a>: type = <span class="stringliteral">&quot;GP2YA21&quot;</span>; <span class="keywordflow">break</span>;
    <span class="keywordflow">case</span> <a name="a7"></a><a class="code" href="group__msdist.html#gaeea311f521348db82b058977609f9898">MSDIST_CUSTOM</a>:  type = <span class="stringliteral">&quot; CUSTOM&quot;</span>; <span class="keywordflow">break</span>;
  }

  nxtDisplayTextLine(5, <span class="stringliteral">&quot;Type: %s&quot;</span>, type);
  nxtDisplayTextLine(6, <span class="stringliteral">&quot;Min:   %4dmm&quot;</span>, mindist);
        nxtDisplayTextLine(7, <span class="stringliteral">&quot;Max:   %4dmm&quot;</span>, maxdist);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// Get the distance calculated based on the data from the IR Sharp module</span>
    distance = <a name="a8"></a><a class="code" href="group__msdist.html#gaeeda2b56ad4d52d5b1193baf5bf88723">MSDISTreadDist</a>(MSDIST);

    <span class="comment">// Get the raw voltage data from the Sharp IR module</span>
    voltage = <a name="a9"></a><a class="code" href="group__msdist.html#ga7219869563624f73f06664d7d2c87e14">MSDISTreadVoltage</a>(MSDIST);
    <span class="keywordflow">if</span> (distance &lt; 0) {
      nxtDisplayTextLine(4, <span class="stringliteral">&quot;ERROR!!&quot;</span>);
      wait1Msec(2000);
      StopAllTasks();
    }

    nxtDisplayCenteredBigTextLine(0, <span class="stringliteral">&quot;%4dmm&quot;</span>, distance);
    nxtDisplayCenteredBigTextLine(3, <span class="stringliteral">&quot;%4dmV&quot;</span>, voltage);
    wait1Msec(50);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-irdist-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
